<template>
  <div class="book-toolbar">
    <ri i="edit" title="编辑" @click="editBook"></ri>
    <ri i="share" title="分享" @click="shareBook"></ri>
    <ri class="grey" i="delete" title="删除" @click="removeBook"></ri>
  </div>
</template>

<script>
export default {
  props: ["bookid"],
  data() {
    return {
    };
  },
  methods: {
    editBook() {
      this.$router.push("/works/books/edit/" + this.bookid);
    },
    shareBook() {
      // TODO: implement this
    },
    removeBook() {
      this.$confirm("确认删除书籍？").then(() => {
        this.authGet("api/v1/books/remove/" + this.bookid)
          .then(() => {
            this.$message("书籍删除成功");
            this.$emit("book-removed", this.bookid);
          })
          .catch(err => {
            this.$message("书籍删除失败！ " + err);
          });
      });
    }
  }
};
</script>

<style lang="stylus" scoped>
.book-toolbar
  float right
  width 160px

  svg
    margin-right 15px
    color #409EFF
    cursor pointer

  .grey
    color #666

    svg
      color #666

  .right
    float right
</style>